<template>
  <div class="index" >
    <div class="item" @click="toNextH5" id="leave">1.点击离开，并记录下当前时间</div>
    <div class="item">当前时间：{{currentTime()}}</div>
    <div class="item">离开时间：{{leaveTime}}</div>
    <div class="item">回到当前页面时间：{{backTime}}</div>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    components: {
    },
    data() {
      return {
        leaveTime:'',
        backTime:''
      }
    },
    methods: {
      toNextH5() {
        this.utils.doRouter(this, '/lifecircleb', null)
      },
      p(s) {
        return s < 10 ? '0' + s: s;
      },
      currentTime() {
        var myDate = new Date();
        var year=myDate.getFullYear();
        var month=myDate.getMonth()+1;
        var date=myDate.getDate();
        var h=myDate.getHours();       //获取当前小时数(0-23)
        var m=myDate.getMinutes();     //获取当前分钟数(0-59)
        var s=myDate.getSeconds();

        return year+'-'+this.p(month)+"-"+this.p(date)+" "+this.p(h)+':'+this.p(m)+":"+this.p(s);
      }
    },
    created() {
        let vue = this
      this.wccia.registerLifecircle(function(status) {
        if ('PAUSED' === status) {
          vue.leaveTime = vue.currentTime();
        } else if ('RESUME' === status){
          vue.backTime = vue.currentTime();
        }
      })
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .index
    display block
    height 6rem
    line-height 6rem
    .item
      height .6rem
      line-height .6rem
      font-size .4rem
      margin .5rem 0 .5rem 0
      &#leave
        text-align center
        font-size .5rem
        border-radius .05rem
        padding .2rem
        background  #ff0000
</style>
